package com.erp.ae.controller;

import com.ruoyi.ae.api.domain.AeHandoverCommitInfo;
import com.ruoyi.ae.api.domain.dto.OrderShipmentForTopDto;
import com.erp.ae.service.IAeLogisticsService;
import com.erp.ae.service.IAeWarehouseOrderInfoService;
import com.ruoyi.common.core.domain.R;
import com.erp.ae.utils.AeApiUtils;
import com.ruoyi.common.core.web.controller.BaseController;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.*;

@Slf4j
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/erp/erpLogistics")
public class AeLogisticsController extends BaseController {

    private final IAeLogisticsService iAeLogisticsService;
    private final IAeWarehouseOrderInfoService iAeWarehouseOrderInfoService;

    /**
     * 线上发货接口
     *
     * @param
     * @return
     * @throws Exception
     */
    @PostMapping("/createWarehouseOrder")
    public R<Object> createWarehouseOrder(@RequestBody Map<String, Object> map) throws Exception {
        //获取店铺的accessToken
        String accessToken = AeApiUtils.getToken((String) map.get("sellerId"));
        if (accessToken != null && !accessToken.equals("")) {
            return iAeLogisticsService.createWarehouseOrder(map, accessToken);
        } else {
            return R.fail("accessToken不存在或已过期");
        }
    }

    /**
     * 同步线上物流订单
     *
     * @param
     * @return
     * @throws Exception
     */
    @PostMapping("/synchronizationWarehouseOrder")
    public R<Object> synchronizationWarehouseOrder(@RequestBody Map<String, Object> map) throws Exception {
        //获取店铺的accessToken
        return iAeLogisticsService.synchronizationWarehouseOrder(map);
    }

    /**
     * 定时任务 线上发货后获取面单 get请求
     *
     * @param
     * @return
     */
    @GetMapping("/queryLogisticsOrderDetail")
    public R<Object> queryLogisticsOrderDetail() {
        return iAeLogisticsService.getOrderOnlineLogisticsLabel();
    }

    /**
     * 获取异步更新的国际运单号
     */
    @GetMapping("/queryLogisticsOrderDetail1")
    public R<Object> queryLogisticsOrderDetailTwo(Long tradeOrderId, String sellerId) {
      return iAeLogisticsService.queryLogisticsOrderDetailTwo(tradeOrderId,sellerId);
    }


    /**
     * 查询线上物流订单状态 post请求
     *
     * @param map
     * @return
     */
    @PostMapping("/queryLogisticsOrderDetail")
    public R<Object> queryLogisticsOrderDetail(
            @RequestBody Map<String, Object> map
    ) {
        return iAeLogisticsService.queryLogisticsOrderDetail(map);
    }

    /**
     * 获取线上发货标签
     *
     * @param internationalLogisticsId
     * @param sellerId
     * @return
     * @throws Exception
     */
    @PostMapping("/getPrintInfo")
    public R<Object> getPrintInfo(String internationalLogisticsId, Long sellerId) throws Exception {
        return iAeLogisticsService.getPrintInfo(internationalLogisticsId,sellerId);
    }

    /**
     * 获取订单可用的物流方案
     */
    @PostMapping("/logisticsServiceQuery")
    public R<Object> logisticsServiceQuery(@RequestBody Map<String, Object> map) throws Exception {
    return iAeLogisticsService.logisticsServiceQuery(map);
    }

    /**
     * 子单声明发货
     */
    @PostMapping("/sellerShipmentForTop")
    public R<Object> sellerShipmentForTop(@RequestBody OrderShipmentForTopDto orderShipmentForTopDto) throws Exception {
      return iAeLogisticsService.sellerShipmentForTop(orderShipmentForTopDto);
    }

    /**
     * 获取线上面单
     */
    @GetMapping("/getprintinfo")
    public R<Object> getprintinfo(String internationalLogisticsId, String sellerId) {
       return iAeLogisticsService.getprintinfo(internationalLogisticsId,sellerId);
    }

    /**
     * 获取店铺收货打包等地址
     *
     * @param sellerId
     * @return
     */
    @GetMapping("/getStoreAddress")
    public R<Object> getStoreAddress(String sellerId) {
      return iAeLogisticsService.getStoreAddress(sellerId);
    }

    /**
     * 交接单提交
     *
     * @param handoverCommitInfo
     * @return
     */
    @PostMapping("/handoverCommit")
    public R<Object> handoverCommit(@RequestBody AeHandoverCommitInfo handoverCommitInfo) {
        return iAeLogisticsService.handoverCommit(handoverCommitInfo);
    }

    /**
     * 获取组包 打包面单Pdf
     *
     * @return
     */
    @PostMapping("/getHandoverPdf")
    public R<Object> getHandoverPdf(
            @RequestBody Map<String, Object> map
    ) {
        return iAeLogisticsService.getHandoverPdf(map);
    }

    /**
     * 查询组包信息
     *
     * @return
     */
    @PostMapping("/handoverContentQuery")
    public R<Object> handoverContentQuery(
            @RequestBody Map<String, Object> map
    ) {
        return iAeLogisticsService.handoverContentQuery(map);
    }

    /**
     * 获取线上发货物流订单信息
     */
    @PostMapping("/getOnlineLogisticsInfo")
    public R<Object> getOnlineLogisticsInfo(
            @RequestBody Map<String, Object> map
    ) {
        return iAeLogisticsService.getOnlineLogisticsInfo(map);
    }


}
